package com.beijing.cyou.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.beijing.cyou.params.RedisParams;
import com.beijing.cyou.redis.RedisBasicService;

@Slf4j
@RestController
@Api(value = "redis控制器", description = "redis数据库帮助API")
public class RedisController {
	
	@Autowired
	private RedisBasicService redisBasicService ;

	@RequestMapping("/getString")
	@ApiOperation(value = "由key得value值" , notes = "redis默认数据库-[0]", httpMethod = "GET")
    public String get(String key) throws Exception {
		log.info("$$$ begin getKey  @@@");
    	String value = redisBasicService.getRedisStringValue(key);
		log.info("@@@ getKey ended  $$$");
        return value;
    }  
	
	@RequestMapping("/{dbnum}/getString")
	@ApiOperation(value = "由key得value值" , notes = "同时指定redis数据库", httpMethod = "GET")
    public String getByDbnum(@PathVariable Integer dbnum,String key) throws Exception {
		log.info("((( getByDbnum-begin getByDbnum  )))))");
    	RedisParams redisParams = new RedisParams(dbnum,key) ;
    	String value = redisBasicService.getRedisStringValueByDbnum(redisParams);
		log.info("((( getByDbnum - end ###  )))))");
        return value;
    }  
		
}
